import React, { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
// import { useAuth } from '../context/AuthContext';
import {useAuthStore} from '../store/authStore';

function AuthRedirect({ children }) {
    const { isAuthenticated } = useAuthStore();
    const navigate = useNavigate();
    console.log('isAuthenticated', isAuthenticated);
    useEffect(() => {
        if (!isAuthenticated) {
            navigate('/login', { replace: true });
        }
    }, [isAuthenticated, navigate]);

    return isAuthenticated ? children : null;
}

export default AuthRedirect;
